package jd;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;

public class Stock {

	public static void main(String[] args) {
		HashMap<Integer, Integer> buyMap = new HashMap<>();
		HashMap<Integer, Integer> sellMap = new HashMap<>();
		Scanner scanner = new Scanner(System.in);
		int count, popular;
		while(scanner.hasNext()){
			count = scanner.nextInt();
			popular = scanner.nextInt();
			buyMap.clear();
			sellMap.clear();
			for(int i = 0; i < count; i++){
				if(scanner.next().equals("B")){
					int price = scanner.nextInt();
					int amount = scanner.nextInt();
					if(buyMap.containsKey(price)){
						buyMap.put(price, buyMap.get(price) + amount);
					}else{
						buyMap.put(price,  amount);
					}
				}else{
					int price = scanner.nextInt();
					int amount = scanner.nextInt();
					if(sellMap.containsKey(price)){
						sellMap.put(price, sellMap.get(price) + amount);
					}else{
						sellMap.put(price,  amount);
					}
				}
			}
			//接下来对map进行排序
			List<Entry<Integer, Integer>> buyList = new ArrayList<>(buyMap.entrySet());
			Collections.sort(buyList, new Comparator<Entry<Integer, Integer>>() {
				@Override
				public int compare(Entry<Integer, Integer> o1,
						Entry<Integer, Integer> o2) {
					return o2.getKey() - o1.getKey();
				}
			});
			List<Entry<Integer, Integer>> sellList = new ArrayList<>(sellMap.entrySet());
			Collections.sort(sellList, new Comparator<Entry<Integer, Integer>>() {
				@Override
				public int compare(Entry<Integer, Integer> o1,
						Entry<Integer, Integer> o2) {
					return o2.getKey() - o1.getKey();
				}
			});
			int sellCount = Math.min(popular, sellList.size());
			for(int i = 0; i < sellCount; i++){
				Entry<Integer, Integer> entry = sellList.get(i);
				System.out.println("S " + entry.getKey() + " " + entry.getValue());
			}
			int buyCount = Math.min(popular, buyList.size());
			for(int i = 0; i < buyCount; i++){
				Entry<Integer, Integer> entry = buyList.get(i);
				System.out.println("B " + entry.getKey() + " " + entry.getValue());
			}
		}
		scanner.close();
//		StringBuilder sb = new StringBuilder();
//		FileInputStream fis = null;
//		int i = 0;
//		try {
//			fis = new FileInputStream(new File(""));
//			while( (i = fis.read()) != -1){
//				sb.append(i);
//			}
//		} catch (IOException e1) {
//			e1.printStackTrace();
//		}
	}
}
